#ifndef __USER_MANAGER_H__
#define __USER_MANAGER_H__

#include "cJSON.h"
#include "common.h"
#include "user.h"

#define USER_NAME_LENGTH    (40)
#define PWD_LENGTH          (20)

#define MAX_USER_COUNT      11

typedef struct _user{
    char username[USER_NAME_LENGTH+1];
    char password[PWD_LENGTH+1];
    char valid;
    char logined;
}user;


typedef struct _usermanager{
    user users[MAX_USER_COUNT];
    int logins;
}usermanager;

#define USER_ERROR_BASE 0

enum user_error{
    ERROR_MORE_THAN_MAX_LONINS = USER_ERROR_BASE + 1,
    ERROR_ALREADY_LOGGED,
    ERROR_NO_FIND_USER,
    ERROR_PASSWORD_WRONG,
    ERROR_USER_NO_LOGINED,
    ERROR_MAXED_USER_COUNT,
    ERROR_NO_AUTHORITY,
    ERROR_USERNAME_OVERLENGTH,
    ERROR_PASSWORD_OVERLENGTH,
    ERROR_CANNOT_DELROOT,
    ERROR_ONLY_CHANGESELF,
    ERROR_USER_UNKNOWN_ID
};

int userloginout(char* username,user_socket* p_user);
cJSON* usermanager_parse(CMD_ID type,cJSON* param,user_socket* user);
void init_usermanager(void);

#endif // !__USER_MANAGER_H__
